{% extends 'base/base1.html' %}
{% load my_tags %}
{% get_category as category %}

{% block title %}
    分类
{% endblock %}

{% block css %}
<style>
    .category-container {
        max-width: 800px;
        margin: 0 auto;
        padding: 30px 20px;
    }
    
    .category-title {
        text-align: center;
        margin-bottom: 30px;
        color: #2c3e50;
        font-size: 28px;
    }
    
    .category-buttons {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
        gap: 20px;
        justify-items: center;
    }
    
    .category-btn {
        display: block;
        width: 100%;
        padding: 15px 25px;
        background-color: #3498db;
        color: white;
        text-align: center;
        text-decoration: none;
        font-size: 16px;
        border-radius: 8px;
        transition: all 0.3s ease;
        border: none;
        cursor: pointer;
    }
    
    .category-btn:hover {
        background-color: #2980b9;
        transform: translateY(-2px);
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
        color: white;
    }
    
    .category-btn:active {
        transform: translateY(0);
    }
</style>
{% endblock %}

{% block main %}
    <div class="category-container">
        <div class="d-flex justify-content-between align-items-center mb-4">
            <h2 class="category-title">商品分类</h2>
            <a href="{% url 'main:category_create' %}" class="btn btn-success">添加分类</a>
        </div>
        
        {% if category %}
        <div class="category-buttons">
            {% for c in category %}
            <div class="category-item">
                <a href="{% url 'main:category_detail' c.id %}" class="category-btn">{{ c.title }}</a>
                <div class="category-actions">
                    <a href="{% url 'main:category_delete' c.id %}" class="btn btn-sm btn-danger delete-btn" onclick="return confirm('确定要删除分类 {{ c.title }} 吗？');">
                        删除
                    </a>
                </div>
            </div>
            {% endfor %}
        </div>
        {% else %}
        <div class="text-center p-5 bg-light rounded">
            <p class="text-muted">暂无分类，请点击上方按钮添加分类</p>
        </div>
        {% endif %}
    </div>

<style>
.category-item {
    position: relative;
    display: inline-block;
    margin: 10px;
}

.category-actions {
    position: absolute;
    top: 100%;
    left: 0;
    display: flex;
    gap: 5px;
    margin-top: 5px;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 10;
}

.category-item:hover .category-actions {
    opacity: 1;
    visibility: visible;
}

.delete-btn {
    padding: 2px 8px;
    font-size: 12px;
}
</style>
{% endblock %}